using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using SmartSoft.DAL;
using System.Data;
using System.Drawing;
using System.Configuration;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class WSSSDataAccess : System.Web.Services.WebService
{    
    public WSSSDataAccess()
    {
        SSDataAccess.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
    }

    [WebMethod]
    public string Backup(string ps_DatabaseName, string ps_FolderName)
    {
        return SSDataAccess.Backup(ps_DatabaseName, ps_FolderName);
    }

    [WebMethod]
    public DataTable CheckInUsed(string ps_FieldName, object po_KeyCode)
    {
        object[] arr = Validator.Validate(po_KeyCode);
        return SSDataAccess.CheckInUsed(ps_FieldName, arr[0]);
    }

    [WebMethod(MessageName = "3Params", Description = "", EnableSession = true)]
    public bool CheckUserRights(string ps_UserName, string ps_FuncType, long pi_FuncID, int pi_Number)
    {
        return SSDataAccess.CheckUserRights(ps_UserName, ps_FuncType, pi_FuncID, pi_Number);
    }

    [WebMethod(MessageName = "4Params", Description = "", EnableSession = true)]
    public bool CheckUserRights(string ps_UserName, string ps_FuncType, string ps_Code, int pi_Number)
    {
        return SSDataAccess.CheckUserRights(ps_UserName, ps_FuncType, ps_Code, pi_Number);
    }

    [WebMethod]
    public string Cong_So_Tt(string ps_Subsidiary)
    {
        return SSDataAccess.Cong_So_Tt(ps_Subsidiary);
    }

    [WebMethod]
    public bool Delete(string ps_TableName, object po_KeyCode)
    {
        object[] arr = Validator.Validate(po_KeyCode);
        return SSDataAccess.Delete(ps_TableName, arr[0]);
    }

    [WebMethod]
    public object GetBuffer(string ps_VarName)
    {
        return SSDataAccess.GetBuffer(ps_VarName);
    }

    [WebMethod]
    public int GetFreeFields(string ps_TableName)
    {
        return SSDataAccess.GetFreeFields(ps_TableName);
    }

    [WebMethod]
    public object GetMemvar(int pi_English, string ps_VarName)
    {
        return SSDataAccess.GetMemvar(pi_English, ps_VarName);
    }

    [WebMethod]
    public byte[] GetPicture(string ps_TableName, string ps_KeyFieldName, object po_KeyData, string ps_FieldPictName, string ps_FieldPictData)
    {
        object[] arr = Validator.Validate(po_KeyData);
        return SSDataAccess.GetPicture(ps_TableName, ps_KeyFieldName, arr[0], ps_FieldPictName, ps_FieldPictData);
    }

    [WebMethod]
    public object GetUservar(string ps_UserName, string ps_VarName)
    {
        return SSDataAccess.GetUservar(ps_UserName, ps_VarName);
    }

    [WebMethod]
    public void MergeCode(string ps_FieldName, object po_OldCode, object po_NewCode)
    {
        object[] arr = Validator.Validate(po_OldCode, po_NewCode);
        SSDataAccess.MergeCode(ps_FieldName, arr[0], arr[1]);
    }

    [WebMethod]
    public void Parameter_Search_Select(string ps_File_Code, ref string ps_FieldList, ref string ps_FieldName, ref string ps_FieldOrder, ref string ps_FilterFieldList, ref bool pb_FilterType, ref bool pb_MatchCase, ref int pi_StartPos, ref int pi_MaxRows, ref bool pb_EachWord)
    {
        SSDataAccess.Parameter_Search_Select(ps_File_Code, ref ps_FieldList, ref ps_FieldName, ref ps_FieldOrder, ref ps_FilterFieldList, ref pb_FilterType, ref pb_MatchCase, ref pi_StartPos, ref pi_MaxRows, ref pb_EachWord);
    }

    [WebMethod]
    public void Restore()
    {
        SSDataAccess.Restore();
    }

    [WebMethod(MessageName = "5Params", Description = "", EnableSession = true)]
    public bool RunSQLCommand(string ps_SQLCommand)
    {
        return SSDataAccess.RunSQLCommand(ps_SQLCommand);
    }

    [WebMethod(MessageName = "6Params", Description = "", EnableSession = true)]
    public bool RunSQLCommand(string ps_SQLCommand, string[] paramsName, object[] paramsValue)
    {        
        return SSDataAccess.RunSQLCommand(ps_SQLCommand, paramsName, paramsValue);
    }

    [WebMethod]
    public bool RunStore(string ps_SQLCommand, string[] paramsName, object[] paramsValue)
    {        
        return SSDataAccess.RunStore(ps_SQLCommand, paramsName, paramsValue);
    }

    [WebMethod]
    public DataTable SelectDataRow(bool ib_EmptyIsValid, string ps_TableName, string ps_FieldName, string ps_FieldValue, string ps_FirstFilter)
    {
        return SSDataAccess.ConvertRowToTable(SSDataAccess.SelectDataRow(ib_EmptyIsValid, ps_TableName, ps_FieldName, ps_FieldValue, ps_FirstFilter));
    }

    [WebMethod]
    public DataTable SelectTable(string ps_SQLCommand)
    {
        return SSDataAccess.SelectTable(ps_SQLCommand);
    }

    [WebMethod]
    public void SetBuffer(string ps_VarName, string ps_VarValue)
    {
        SSDataAccess.SetBuffer(ps_VarName, ps_VarValue);
    }

    [WebMethod(MessageName = "7Params", Description = "", EnableSession = true)]
    public void SetMemvar(string ps_VarName, string ps_VarValue)
    {
        SSDataAccess.SetMemvar(ps_VarName, ps_VarValue);
    }

    [WebMethod(MessageName = "8Params", Description = "", EnableSession = true)]
    public void SetMemvar(string ps_VarName, string ps_VarValue, string ps_VarValueE)
    {
        SSDataAccess.SetMemvar(ps_VarName, ps_VarValue, ps_VarValueE);
    }

    [WebMethod]
    public bool SetPicture(string ps_TableName, string ps_KeyFieldName, object po_KeyData, string ps_FieldPictName, string ps_FieldPictData, string fileName, byte[] buffer)
    {
        object[] arr = Validator.Validate(po_KeyData);
        return SSDataAccess.SetPicture(ps_TableName, ps_KeyFieldName, arr[0], ps_FieldPictName, ps_FieldPictData, fileName, buffer);
    }

    [WebMethod]
    public void SetUservar(string ps_UserName, string ps_VarName, string ps_VarValue)
    {
        SSDataAccess.SetUservar(ps_UserName, ps_VarName, ps_VarValue);
    }
}